package Java.BlackHorse.a05IOTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test2 {
    /*
    * 拷贝文件夹。包括子文件
    * */
    public static void main(String[] args) throws  IOException{
        File data = new File("IO\\CharStream\\aaa");
        File dest = new File("IO\\CharStream\\bbb");

        copyDir(data,dest);
    }

    private static void copyDir(File data, File dest) throws IOException {
        dest.mkdirs();
        byte[] read = new byte[1024];
        int len;
        File[] listfile = data.listFiles();

        for(File f : listfile){
            if(f.isFile()) {
                FileInputStream fis = new FileInputStream(f);
                FileOutputStream fos = new FileOutputStream(new File(dest,f.getName()));
                while((len= fis.read(read)) != -1){
                    fos.write(read,0,len);
                }
                fos.close();
                fis.close();
            }else{
                copyDir(f,new File(dest,f.getName()));
            }
        }
    }

}
